// Copyright 2009 Vladimir Solomenchuk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
dojo.provide("judo.base");


judo.addOnLoad=function(func, priority){
	judo.addOnLoad[typeof priority!="undefined"?"_priorityStack":"_stack"].push(func);
}

judo.addOnLoad._stack=[];
judo.addOnLoad._priorityStack=[];

dojo.addOnLoad(function(){
	for (var i=0;i<judo.addOnLoad._priorityStack.length;i++)
		judo.addOnLoad._priorityStack[i](arguments);
	
	for (var i=0;i<judo.addOnLoad._stack.length;i++)
		judo.addOnLoad._stack[i](arguments);

	judo.addOnLoad=dojo.addOnLoad;
})

judo.nById=function(/* String */ id){
	var node=dojo.byId(id);
	if (!node)
		dojo.query('[id^="'+id+'-"]').forEach(function(n){
			node=n;
		});
	return node;
}

judo.wById=function(/* String */ id){
	var widget=dijit.byId(id);
	if (!widget)
		dojo.query('[widgetid^="'+id+'-"]').forEach(function(n){
			widget=dijit.byNode(n);
		});
	return widget;
}